package com.net.xpay.openapi.helper;

import com.google.common.base.Strings;
import com.net.xpay.common.domain.openapi.OpenImage;
import com.net.xpay.common.manager.openapi.OpenImageManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 2020/6/28 10:39
 * 白名单IP验证
 */
@Slf4j
@Component
public class ImageIdHelper {
    @Autowired
    private OpenImageManager openImageManager;

    public String fetchImageUrl(String imageId) {
        if (Strings.isNullOrEmpty(imageId)) {
            return null;
        }
        OpenImage openImage = openImageManager.getByImageId(imageId);
        if (openImage != null) {
            return openImage.getImageUrl();
        }
        return null;
    }


    public List<String> fetchImageUrls(List<String> imageIds) {
        List<String> ret = new ArrayList<>();
        for (String image : imageIds) {
            if (Strings.isNullOrEmpty(image)) {
                return null;
            }
            String imageUrl = fetchImageUrl(image);
            if (Strings.isNullOrEmpty(imageUrl)) {
                return null;
            }
            ret.add(imageUrl);
        }
        return ret;
    }
}
